home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 343_02 / mainfilt.c < prev    next >
Text File  |  1992-03-26  |  4KB  |  137 lines

  1.  
  2.  
  3.  
  4.  
  5.        /***********************************************
  6.        *
  7.        *       file d:\cips\mainfilt.c
  8.        *
  9.        *       Functions: This file contains
  10.        *          main
  11.        *
  12.        *       Purpose:
  13.        *          This file contains the main calling
  14.        *          routine in an image filtering program.
  15.        *
  16.        *       External Calls:
  17.        *          gin.c - get_image_name
  18.        *          numcvrt.c - get_integer
  19.        *                      int_convert
  20.        *          tiff.c - read_tiff_header
  21.        *          filter.c - filter_image
  22.        *                     median_filter
  23.        *
  24.        *       Modifications:
  25.        *          15 February 1992 - created
  26.        *
  27.        *************************************************/
  28.  
  29. #include "d:\cips\cips.h"
  30.  
  31.  
  32.  
  33. short the_image[ROWS][COLS];
  34. short out_image[ROWS][COLS];
  35.  
  36. main(argc, argv)
  37.    int argc;
  38.    char *argv[];
  39. {
  40.  
  41.    char     name[80], name2[80], low_high[80];
  42.    int      count, i, ie, il, j, le, length, ll, lw,
  43.             type, width;
  44.    short    filter[3][3];
  45.    struct   tiff_header_struct image_header;
  46.  
  47.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  48.    _setbkcolor(1);
  49.    _settextcolor(7);
  50.    _clearscreen(_GCLEARSCREEN);
  51.  
  52.        /***********************************************
  53.        *
  54.        *       Interpret the command line parameters.
  55.        *
  56.        ************************************************/
  57.  
  58.    if(argc < 5){
  59.     printf(
  60.     "\n\nNot enough parameters:"
  61.      "\n"
  62.      "\n usage: mainfilt in-file out-file type low-or-high-pass"
  63.      "\n"
  64.      "\n   recall type: 6, 9, 10, 16 for low pass"
  65.      "\n   recall type: 1, 2, 3 for high pass"
  66.      "\n   recall type: is the size of the nxn area for median filtering"
  67.      "\n   low-or-high-pass l=low pass h=high pass "
  68.     "\n                    m=median filter "
  69.      "\n");
  70.     exit(0);
  71.    }
  72.  
  73.    strcpy(name, argv[1]);
  74.    strcpy(name2, argv[2]);
  75.    int_convert(argv[3], &type);
  76.    strcpy(low_high, argv[4]);
  77.  
  78.    il = 1;
  79.    ie = 1;
  80.    ll = ROWS+1;
  81.    le = COLS+1;
  82.  
  83.        /***********************************************
  84.        *
  85.        *       Read the input image header and setup 
  86.        *       the looping counters.
  87.        *
  88.        *       If high or low pass filtering, setup
  89.        *       the filter mask array.
  90.        *
  91.        ************************************************/
  92.  
  93.    read_tiff_header(name, &image_header);
  94.  
  95.    length = (90 + image_header.image_length)/ROWS;
  96.    width  = (90 + image_header.image_width)/COLS;
  97.    count  = 1;
  98.    lw     = length*width;
  99.    printf("\nlength=%d  width=%d", length, width);
  100.  
  101.    if(low_high[0] == 'l' ||
  102.       low_high[0] == 'L' ||
  103.       low_high[0] == 'h' ||
  104.       low_high[0] == 'H')
  105.          setup_filters(type, low_high, filter);
  106.  
  107.        /***********************************************
  108.        *
  109.        *       Loop over the input image and filter it
  110.        *       using either the high or low pass filters
  111.        *       using a mask OR using the median filter.
  112.        *
  113.        ************************************************/
  114.  
  115.    for(i=0; i<length; i++){
  116.       for(j=0; j<width; j++){
  117.          printf("\nrunning %d of %d", count, lw);
  118.          count++;
  119.  
  120.          if(low_high[0] == 'l' ||
  121.             low_high[0] == 'L' ||
  122.             low_high[0] == 'h' ||
  123.             low_high[0] == 'H')
  124.               filter_image(name, name2, the_image, out_image,
  125.                            il+i*ROWS, ie+j*COLS, ll+i*ROWS,
  126.                            le+j*COLS, filter, type);
  127.  
  128.          if(low_high[0] == 'm' ||
  129.             low_high[0] == 'M')
  130.               median_filter(name, name2, the_image, out_image,
  131.                            il+i*ROWS, ie+j*COLS, ll+i*ROWS,
  132.                            le+j*COLS, type);
  133.  
  134.  
  135.       }  /* ends loop over j */
  136.    }  /* ends loop over i */
  137. }  /* ends main  */